<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>

<script type="text/javascript">
    var rowId = 0;
    $('fbox_borrowersGrid .ui-reset , #refresh_borrowersGrid').click(function(){
        $("#borrowersGrid").jqGrid('setGridParam',{search:false});
        var postData = $("#borrowersGrid").jqGrid('getGridParam','postData');
        $.extend(postData,{searchField:"",searchString:"",searchOper:""});
        $.extend(postData,{filters:""});
        $("#borrowersGrid").trigger("reloadGrid");
    });

    $.subscribe('searchBorrowersGrid', function(event,data) {
        $("#borrowersGrid").jqGrid('searchGrid', {closeAfterSearch:true,closeOnEscape:true,sopt:['eq'],caption:"Search Borrowers"} );
    });
    
    $.subscribe('showhideBorrowersGrid', function(event,data) {
        $("#borrowersGrid").jqGrid('setColumns',{});
    });
    
    $.subscribe('borrowersGridComplete',function(event,data){
        $( "#borrowersGrid_showhide" ).button( "option", "disabled", false );
        $( "#borrowersGrid_search" ).button( "option", "disabled", false );
    });

</script>
<div class="gridOptsContainer">
    <sj:submit button="true" cssStyle="font-size:14px;" disabled="true" id="borrowersGrid_search" onClickTopics="searchBorrowersGrid" value="Search Borrower"/>
    <sj:submit button="true" cssStyle="font-size:14px;" disabled="true" id="borrowersGrid_showhide" onClickTopics="showhideBorrowersGrid" value="Show/Hide Columns"/>
</div>
<s:url id="remoteurl" action="grid-borrower"/>
<s:url id="editurl" action="edit-borrower"/>
<s:url id="selectOptionsBranches" action="select-branches"/>
<s:url id="selectOptionsAreas" action="select-areas"/>
<sjg:grid
    id="borrowersGrid"
    caption="Cashmate Borrowers"
    cellEdit="true"
    dataType="json"
    href="%{remoteurl}"
    cellurl="%{editurl}"
    gridModel="gridModel"
    pagerButtons="true"
    pagerInput="true"
    rowList="15,30,50"
    rowNum="15"
    loadingText="Requesting Data..."
    width="970"
    shrinkToFit="true"
    pager="true"
    hoverrows="true"
    rownumbers="true"
    autoencode="true"
    viewrecords="true"
    navigator="true"
    navigatorAdd="false"
    navigatorDelete="false"
    navigatorEdit="false"
    navigatorSearch="true"
    navigatorSearchOptions="{closeAfterSearch:true,closeOnEscape:true,sopt:['eq'],caption:'Search Borrower'}"
    navigatorView="true"
    onGridCompleteTopics="borrowersGridComplete"
    onSelectRowTopics="borrowersGridRowSelected"
    onCellEditSuccessTopics=""
    >

    <sjg:gridColumn name="borrowerid"
                    index="borrowerid"
                    title="Borrower ID"
                    sortable="false"
                    key="true"
                    hidden="true"
                    />

    <sjg:gridColumn name="borrowercode"
                    index="borrowercode"
                    title="Borrower Code"
                    search="true"
                    sortable="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="firstname"
                    index="firstname"
                    title="First Name"
                    search="true"
                    sortable="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="middlename"
                    index="middlename"
                    title="Middle Name"
                    sortable="true"
                    align="center"
                    hidden="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="lastname"
                    index="lastname"
                    title="Last Name"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="branchname"
                    index="branchname"
                    title="Branch"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    editable="true"
                    edittype="select"
                    editoptions="{dataUrl : '%{selectOptionsBranches}'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="areacode"
                    index="areacode"
                    title="Area Code"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    editable="true"
                    edittype="select"
                    editoptions="{dataUrl : '%{selectOptionsAreas}'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="religion"
                    index="religion"
                    title="Religion"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    hidden="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="civilstatus"
                    index="civilstatus"
                    title="Civil Status"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    hidden="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="dateofbirth"
                    index="dateofbirth"
                    title="Date of Birth"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    editable="true"
                    hidden="true"
                    edittype="text"
                    editoptions="{maxlength:'9'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="age"
                    index="age"
                    title="Age"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    hidden="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'2'}"
                    editrules="{required:true,number:true}"
                    />

    <sjg:gridColumn name="placeofbirth"
                    index="placeofbirth"
                    title="Place of Birth"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    hidden="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="citizenship"
                    index="citizenship"
                    title="Citizenship"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    hidden="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="streetaddress"
                    index="streetaddress"
                    title="Street Address"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    hidden="true"
                    align="center"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="barangay"
                    index="barangay"
                    title="Barangay"
                    search="true"
                    hidden="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="cityormunicipality"
                    index="cityormunicipality"
                    title="City/Municipality"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="province"
                    index="province"
                    title="Province"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'45'}"
                    editrules="{required:true}"
                    />

    <sjg:gridColumn name="postalcode"
                    index="postalcode"
                    title="Postal Code"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    hidden="true"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'4'}"
                    editrules="{required:true,number:true}"
                    />

    <sjg:gridColumn name="contactnumber"
                    index="contactnumber"
                    title="Contact Number"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    editable="true"
                    edittype="text"
                    editoptions="{maxlength:'20'}"
                    />
</sjg:grid>